<script type="text/javascript">
function submitForm(idForm){
	var result = tmt.validator.validateForm(idForm);
	if(result){
		document.forms[idForm].submit();
	}
}
function updateForm(){
	var xhrSearch = getXmlHttpRequest2();
	
	var idClient = document.getElementById('item_chiffre_affaires_client_id').value;
	var idFournisseur = document.getElementById('chiffre_affaires_fournisseur_id').value;
	var annee = document.getElementById('chiffre_affaires_annee').value;
	var mois = document.getElementById('chiffre_affaires_mois').value;
	if(idClient == ''){
		document.getElementById('chiffre_fields').innerHTML = "";
	}else{
		if(document.getElementById('chiffre_fields')){
			document.getElementById('chiffre_fields').innerHTML = '<img style="width:50%;height:25px;" alt="wait please..." src="/images/ajax-loader.gif">';
		}
		xhrSearch.open("POST","<?php print url_for('chiffres/updateChiffresForm'); ?>",false);
		xhrSearch.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var fieldName='';
		xhrSearch.send("idClient="+idClient+"&idFournisseur="+idFournisseur + "&annee=" + annee + "&mois=" + mois);
		var xHtml = xhrSearch.responseText;
		document.getElementById('chiffre_fields').innerHTML = xhrSearch.responseText;	
	}		
}

</script>
<fieldset><legend><?php echo __('Input Turnover')?></legend>
<form id="Formchiffre_affaire" action="<?php print url_for('chiffres/ChiffrePhase1'); ?>" method="post" tmt:validate = "true" tmt:callback="errorOnLabels" target="showChiffres">
<input type="hidden" name="sf_method" value="put" />
<?php
		echo $form->renderGlobalErrors();
		
		if ($form->isCSRFProtected())
		 	echo $form['_csrf_token'];
		 	echo $objDef->renderAttributeWidget($form, 'id');
		    echo $objDef->renderAttributeWidget($form, 'annee');
			echo $objDef->renderAttributeWidget($form, 'mois');
			echo $objDef->renderAttributeWidget($form, 'fournisseur');
			echo $objDefItem->renderAttributeWidget($form_item, 'client');
?>
<div id="chiffre_fields"></div>
<div class="buttons">		  	
<?php echo link_to('<img title="'.__('Go back').'" src="/images/icons/64/cancel.png"/>', 'defaultViewer/index?className=chiffre_affaires');?>
<a href="javascript:submitForm('Formchiffre_affaire');">			
<img src="/images/icons/64/confirm.png" title="<?php echo __('Save')?>"></img>
</a>
</div>
</form> 	
</fieldset>

<iframe id="showChiffres" src="#" style="width:100%;border:0px solid #fff;" name="showChiffres"></iframe>